<template>
	<view>
		<!-- <u-navbar back-text="返回" :title="appBusiness.name"></u-navbar> -->
		<u-navbar :is-back="false" title="">
			<view class="slot_wrap">
				<u-icon @click="handleBack" name='arrow-left'></u-icon>
				<u-input @blur='inpFocus=false' placeholder="请输入搜索商品名称" v-if="inpFocus" :focus='inpFocus'
					v-model="searchValue" type="text" :border="false" />
				<view class="" v-else>
					{{searchValue}}
				</view>
				<u-icon v-if="inpFocus==false" name='search' @click="handSearchShowInp"></u-icon>
				<view v-else class="search_sub" @click="handleSubSearch">
					确定
				</view>
			</view>
		</u-navbar>
		<view class="shop_msg u-border-bottom">
			<image class="icon" :src="appBusiness.imgUrl" mode="">
			</image>
			<view class="msg">
				<view class="title_box">
					<view class="title">
						{{appBusiness.name}}
					</view>
					<view class="go">
						<u-tag @click="followAppBusiness" v-if="appBusiness.isFollow=='1'" text="已关注" size='mini'
							mode='plain' />
						<u-button @click="followAppBusiness" size='mini' plain v-else>关注</u-button>
					</view>
				</view>
				<view class="num_box">
					已卖出：{{appBusiness.salesVolume}}件 | {{appBusiness.followCount}}人关注
				</view>
			</view>
		</view>
		<view class="score_box_content">
			<view class="score_box">
				<view class="title">
					评论: ({{commentNum}})
				</view>
				<u-rate size="mini" active-color='#FF365D' :current="appBusiness.score" :disabled="true"></u-rate>

			</view>
			<view class="distance">
				<u-icon color="#ff365d" name="map"></u-icon> 距离{{distance}}km
			</view>

		</view>
		<view class="score_box_content" v-if="appBusiness.enterpriseIntroduce">
			{{appBusiness.enterpriseIntroduce}}
		</view>
		<u-gap height="14" bg-color="#ECECEC"></u-gap>
		<view class="all_shop_title">
			全部商品
		</view>
		<u-empty v-if="list.length==0"></u-empty>
		<view class="goods_row" v-else>
			<GoodsItemRow @handNavToDetails='handNavToDetails(item)' v-for="(item,index) in list" :item='item'
				:key='index'></GoodsItemRow>
		</view>
	</view>
</template>

<script>
	import GoodsItemRow from '@/components/ZY-Goods-item-row/ZY-Goods-item.vue'
	import initData from '@/mixin/initData.js'
	import {
		getMapDistance
	} from '@/utils/utils.js'
	export default {
		mixins: [initData],
		components: {
			GoodsItemRow
		},
		data() {
			return {
				appBusiness: {},
				searchValue: '',
				inpFocus: false,
			};
		},
		computed: {
			distance() {
				const longitude = this.cache.getCache('longitude')
				const latitude = this.cache.getCache('latitude')
				if (latitude && longitude) {
					return (getMapDistance(latitude, longitude, this.appBusiness.lat, this.appBusiness.lng)).toFixed(2)
				}
			},
			commentNum() {
				return this.appBusiness.commentCount >= 999 ? '999+' : this.appBusiness.commentCount
			}
		},
		onLoad(e) {
			if (e && e.id) {
				this.id = e.id
				this.init()
				this.miXinInit()
			}
		},
		methods: {
			handNavToDetails(item) {
				uni.navigateTo({
					url: '/pages/followShop/goodsDetail/goodsDetail?id=' + item.id,

				})
			},
			followAppBusiness() {
				this.$u.api.followAppBusiness({
					id: this.appBusiness.id
				}).then(res => {
					uni.showToast({
						icon: 'none',
						title: this.appBusiness.isFollow == 2 ? '关注成功!' : '取消关注'
					})
					this.init()
				})
			},
			handleBack() {
				uni.navigateBack({

				})
			},
			handleSubSearch() {
				this.toReset()
				this.miXinInit()
				this.inpFocus = false
			},
			handSearchShowInp() {
				this.inpFocus = true
			},
			// 请求前的参数处理
			beforeInit() {
				this.apiUrl = "appBusiness/appBusinessGoodsList";
				let params = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					id: this.id,
					title: this.searchValue
				};

				this.params = {
					...params
				};
			},
			init() {

				this.$u.api.appBusinessInfo({
					id: this.id
				}).then(res => {
					console.log(res, '商家详情')
					this.appBusiness = res
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.distance {
		color: $u-type-primary;
		margin-left: 10rpx;
	}

	.slot_wrap {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
		padding: 0 15rpx;
	}

	.goods_row {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.all_shop_title {
		text-align: center;
		margin: 22rpx 0;
		font-size: 30rpx;
		font-weight: 600;
		color: $u-type-primary;
	}

	.score_box_content {
		display: flex;
		padding: 16rpx 24rpx;
		width: 100%;
		justify-content: space-between;
	}

	.score_box {
		display: flex;
		align-items: center;


		.title {
			margin-right: 24rpx;
			font-size: 28rpx;
			color: #535353;
		}
	}

	.num_box {
		font-size: 22rpx;
		color: #B9B9B9;
	}

	.shop_msg {
		padding: 24rpx;
		display: flex;
		align-items: center;

		// justify-content: space-between;
		.icon {
			width: 83rpx;
			height: 83rpx;
			min-width: 83rpx;
			margin-right: 25rpx;
		}

		.msg {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			width: 100%;
			height: 83rpx;

			.title_box {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;

				.go {
					color: #646464;
					font-size: 24rpx;
				}

				.title {
					color: #101010;
					font-size: 34rpx;
					font-weight: 600;
				}
			}
		}
	}
</style>
